home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / ftpdaemon.lha / amimsgd / amimsgd.c < prev   
C/C++ Source or Header  |  1993-10-13  |  2KB  |  97 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <netdb.h>
  5. #include <sys/types.h>
  6. #include <sys/syslog.h>
  7. #include <netinet/in.h>
  8. #include <lineread.h>
  9.  
  10. //#include <intuition/intuition.h>
  11.  
  12. #include <proto/dos.h>
  13. #include <proto/exec.h>
  14. //#include <proto/intuition.h>
  15.  
  16. char user[15];
  17. char host[20];
  18. char msg[40];
  19. char Title[80];
  20.  
  21. struct sockaddr_in his_addr;
  22. long addrlen;
  23. struct LineRead lr;
  24.  
  25. //struct IntuitionBase *IntuitionBase;
  26. //struct EasyStruct es={
  27. //    sizeof(struct EasyStruct),
  28. //    0,
  29. //    NULL,NULL,"Ok"
  30. //};
  31.  
  32. extern long server_socket;
  33. long gethostname(char *,long len);
  34.  
  35. void main(void)
  36. {
  37.     fd_set readfds;
  38.     int length,i;
  39.     
  40.     if(server_socket==-1) exit(20);
  41.     
  42. //    IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
  43. //    if(!IntuitionBase) exit(20);
  44.     
  45.     addrlen = sizeof (his_addr);
  46.     if(getpeername(0,(struct sockaddr *)&his_addr, &addrlen)<0) exit(20);
  47.     
  48.     // drie regels ophalen van het formaat
  49.     // HOST hostname:20
  50.     // USER username:10
  51.     // MSG message:40
  52.     
  53.     initLineRead(&lr,server_socket,RL_LFREQNUL,160);
  54.     FD_ZERO(&readfds);
  55.     
  56.     i=0;
  57.     while((i&7)!=7)
  58.     {
  59.         FD_SET(server_socket,&readfds);
  60.         if(select(server_socket+1,&readfds,NULL,NULL,NULL)<0) exit(20);
  61.         if(FD_SET(server_socket,&readfds))
  62.         {
  63.             length=lineRead(&lr);
  64.             if(length==-1) exit(20);
  65.             if(lr.rl_Line)
  66.             {
  67.                 if(!strncmp("HOST ",lr.rl_Line,5))
  68.                 {    
  69.                     strncpy(host,lr.rl_Line+5,sizeof(host));
  70.                     host[sizeof(host)-1]='\0';
  71.                     i|=1;
  72.                 }
  73.                 if(!strncmp("USER ",lr.rl_Line,5))
  74.                 {
  75.                     strncpy(user,lr.rl_Line+5,sizeof(user));
  76.                     user[sizeof(user)-1]='\0';
  77.                     i|=2;
  78.                 }
  79.                 if(!strncmp("MSG ",lr.rl_Line,4))
  80.                 {
  81.                     strncpy(msg,lr.rl_Line+4,sizeof(msg));
  82.                     msg[sizeof(msg)-1]='\0';
  83.                     i|=4;
  84.                 }
  85.             }
  86.         }        
  87.     }
  88.     CloseSocket(server_socket);
  89.     
  90. //    sprintf(Title,"Message from: %s",inet_ntoa(his_addr.sin_addr));
  91. //    es.es_Title=Title;
  92. //    es.es_TextFormat="%s: %s\n%s";
  93. //    EasyRequest(NULL,&es,0,host,user,msg);
  94.  
  95.     syslog(LOG_INFO,"%s@%s(%s): %s",user,host,inet_ntoa(his_addr.sin_addr),msg);
  96. }
  97.